#ifndef GENERATE_H_
#define GENERATE_H_

#ifndef SYMTAB_H_
#include "symtab.h"
#endif

#define BLC_HDR_TERMSYMTAB_SIZE     (0)
#define BLC_HDR_NONTERMSYMTAB_SIZE  (2)
#define BLC_HDR_ENTRYTABLE_SIZE     (4)
#define BLC_HDR_SELECTTABLE_SIZE    (6)
#define BLC_HDR_RULEOPCODE_SIZE     (8)

#define BLC_HDR_SIZE                (10)

typedef unsigned char   BLC_OPCODE;

typedef struct  INTVECTOR
    {
    int*        v;
    int         Size;
    }           INTVECTOR;

typedef struct  TParseTables
    {
    BLC_OPCODE* Opcodes;
    int         SelSectOfs;
    int         RuleSectOfs;
    int         NOpcodes;
    size_t      OpcodeSize;
    INTVECTOR   LLColumns;      /* lists of terminals       */
    INTVECTOR   LLRows;         /* lists of rule numbers    */
    INTVECTOR   LLRowStarts;    /* offsets of row beginnings*/
    INTVECTOR   RuleOffsets;    /* offsets into Opcodes     */
    int         SelectStart;    /* offset into SelectOffsets of start symbol */
    int         NRules;
    TRule**     Rules;          /* list of unique rules     */
    SYMBOLS*    RuleSymbols;    /* parallel to Rules        */
    int         MaxTokenVal;
    int         MinTokenVal;
    SYMBOLS     LLNonTerms;
    int         TokenMatchAny;
    int         TokenEol;
    }           TParseTables;

enum
    {
    BLCOP_MATCH     =0x00,      /* MATCH        [token_id]                  */
    BLCOP_CALL      =0x01,      /* CALL         [16-bit rule offset]        */
    BLCOP_TAILSELECT=0x02,      /* TAILSELECT   [pop] [16-bit selset ofs]   */
    BLCOP_LLSELECT  =0x03,      /* LLSELECT     [16-bit selset offset]      */
    BLCOP_ACTRED    =0x04,      /* ACTRED       [action_id, reduce_count]   */
    BLCOP_REDUCE    =0x05,      /* REDUCE       [reduce_count]              */
    BLCOP_HALT      =0x06,      /* HALT                                     */
    BLCOP_SHIFTSEL  =0x07,      /* SHIFTSEL                                 */
    BLCOP_ACTION8   =0x08,      /* ACTION       [action_id]                 */
    };

TParseTables* GenerateParseTables(void);
void          FreeParseTables(TParseTables* Tables);

#endif  /* GENERATE_H_ */





